package cn.edu.neusoft.maxingxin231.yuejian06.Fragment.activityFragment;

import android.content.Context;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;

import java.util.List;

import cn.edu.neusoft.maxingxin231.yuejian06.Adapter.MasterAdapter;
import cn.edu.neusoft.maxingxin231.yuejian06.Adapter.RecentRaceAdapter;
import cn.edu.neusoft.maxingxin231.yuejian06.Bean.MasterBean;
import cn.edu.neusoft.maxingxin231.yuejian06.Bean.RecentRaceBean;
import cn.edu.neusoft.maxingxin231.yuejian06.Listener.ListListener;
import cn.edu.neusoft.maxingxin231.yuejian06.Model.MasterModel;
import cn.edu.neusoft.maxingxin231.yuejian06.Model.RecentRaceModel;
import cn.edu.neusoft.maxingxin231.yuejian06.R;


public class RecentRaceFragment extends Fragment {

    private View view=null;
    private Context context;
    private RecyclerView recycleview_recent;
    private RecyclerView.LayoutManager layoutManager;
    private RecentRaceAdapter recentRaceAdapter;
    private List<RecentRaceBean> items=null;
    ListListener<RecentRaceBean> recentRaceBeanListListener=new ListListener<RecentRaceBean>() {
        @Override
        public void onResponse(List<RecentRaceBean> list) {
            Toast.makeText(context, "success", Toast.LENGTH_SHORT).show();
            items = list;
            recentRaceAdapter.setList(list);
        }

        @Override
        public void onFail(String msg) {
            Toast.makeText(context,"fail:"+msg,Toast.LENGTH_SHORT).show();
        }
    };

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        context=getActivity();
        view=inflater.inflate(R.layout.fragment_recent_race, container, false);
        recycleview_recent=(RecyclerView) view.findViewById(R.id.recycle_recent);
        layoutManager=new LinearLayoutManager(context);
        recycleview_recent.setLayoutManager(layoutManager);
        recentRaceAdapter=new RecentRaceAdapter(getActivity(),items,R.layout.club_card);
        recentRaceAdapter.setList(items);

        recycleview_recent.setAdapter(recentRaceAdapter);
        RecentRaceModel recentRaceModel = new RecentRaceModel();
        recentRaceModel.getRecentRaceList(recentRaceBeanListListener);
        return view;
    }

    public interface OnFragmentInteractionListener {
        // TODO: Update argument type and name
        void onFragmentInteraction(Uri uri);
    }
}
